import 'package:flutter/material.dart';
import 'package:flutter_module/base/base.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:flutter_riverpod/legacy.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';

// 定义类似全局的 状态 Model
final riverpodProvider = StateProvider((Ref ref) => 0);
final riverpodProvider2 = StateProvider((Ref ref) => 0);

// ViewModel
class RiverpodViewModel {

}


// View
class PageRiverpodState extends BaseWidget {
  const PageRiverpodState({super.key});

  @override
  Widget setContent(BuildContext context) {
    return ProviderScope(
      child: Consumer(
        builder: (context, ref, _) {
          print("创建 widget");
          return Column(
            mainAxisAlignment: MainAxisAlignment.center,
            crossAxisAlignment: CrossAxisAlignment.center,
            children: [
              Text(
                "Riverpod",
                style: TextStyle(color: Colors.black, fontSize: 36.w),
              ),
              Expanded(child: Container()),
              Text(
                "${ref.watch(riverpodProvider)}",
                style: TextStyle(color: Color(0xFF333333), fontSize: 24.w),
              ),
              TextButton(
                onPressed: () {
                  ref.watch(riverpodProvider.notifier).state++;
                },
                child: Text("Count ++", style: TextStyle(fontSize: 24.w)),
              ),
              Text(
                "${ref.watch(riverpodProvider2)}",
                style: TextStyle(color: Color(0xFF333333), fontSize: 24.w),
              ),
              TextButton(
                onPressed: () {
                  ref.watch(riverpodProvider2.notifier).state++;
                },
                child: Text("Count ++", style: TextStyle(fontSize: 24.w)),
              ),
              Expanded(child: Container()),
            ],
          );
        },
      ),
    );
  }
}
